// 运行结果：ConcreteProductA: Result of operation
// ConcreteProductB: Result of operation
// Product.java
public abstract class Product {
    public abstract void operation();
}
// ConcreteProductA.java
public class ConcreteProductA extends Product {
    @Override
    public void operation() {
        System.out.println("ConcreteProductA: Result of operation");
    }
}
// ConcreteProductB.java
public class ConcreteProductB extends Product {
    @Override
    public void operation() {
        System.out.println("ConcreteProductB: Result of operation");
    }
}
// Factory.java
public class Factory {
    public Product factoryMethod(String choice) {
        if ("A".equalsIgnoreCase(choice)) {
            return new ConcreteProductA();
        } else if ("B".equalsIgnoreCase(choice)) {
            return new ConcreteProductB();
        }
        return null;
    }
}
// Client.java
public class Client {
    public static void main(String[] args) {
        Factory factory = new Factory();
        
        Product productA = factory.factoryMethod("A");
        if (productA != null) {
            productA.operation();
        }
        
        Product productB = factory.factoryMethod("B");
        if (productB != null) {
            productB.operation();
        }
    }
}